//=============================================================================
// Sky.fx by Frank Luna (C) 2011 All Rights Reserved.
//=============================================================================

// Include common HLSL code.
#include "Common.hlsl"

struct VertexIn
{
	//float3 PosL    : POSITION;
	//float3 NormalL : NORMAL;
	//float2 TexC    : TEXCOORD;
	
    float3 PosL : POSITION;
    float3 NormalL : NORMAL;
    float2 TexC : TEXCOORD;
    float3 TangentU : TANGENT;
    float4 BoneWeights : WEIGHTS;
    int4 BoneIndices : BONEINDICES;
};

struct VertexOut
{
	float4 PosH : SV_POSITION;
    float3 PosL : POSITION;
};
 
VertexOut VS(VertexIn vin)
{
	VertexOut vout;

	// Use local vertex position as cubemap lookup vector.
	vout.PosL = vin.PosL;
	
	// Transform to world space.
	float4 posW = mul(float4(vin.PosL, 1.0f), gWorld);

	// Always center sky about camera.
	posW.xyz += gEyePosW;

	// Set z = w so that z/w = 1 (i.e., skydome always on far plane).
	vout.PosH = mul(posW, gViewProj).xyww;
	
	return vout;
}
TextureCube BaseColorTexture;
float4 PS(VertexOut pin) : SV_Target
{
    float4 color = BaseColorTexture.Sample(gsamLinearWrap, pin.PosL);
    float fade = 1.0f;
    if (gLightCount > 0)
    {
        fade = 0.0f;
        for (uint i = 0; i < gLightCount; i++)
        {
            if (gLights[i].LightType == 0)
                fade += gLights[i].Intensity;
        }
        fade = fade / gLightCount;
        fade = clamp(fade, 0.0f, 1.0f);

    }
    return color * fade + float4(color.xyz * gAmbientLight.xyz, 0); // +cbMaterialData.DiffuseAlbedo

}

